<?php
require_once("include.php");
function __autoload($classname) {
require_once("registereduserobj.php");
}
require_once ("navbar.php");
authorise("userinput");
if (!(isset($_SESSION["registereduser"]))) {$obj = new registereduser();}
$obj=&$_SESSION["registereduser"] ; // Point to the objext in the session

// Code from here down is likely to be the same for every manager
(isset($_REQUEST["restart"])) ? $restart = $_REQUEST["restart"] : $restart = "NULL" ;
(isset($_REQUEST["res"])) ? $res = $_REQUEST["res"] : $res = "NULL" ;
(isset($_REQUEST["sub"])) ? $sub = $_REQUEST["sub"] : $sub = "NULL" ;
(isset($_REQUEST["itemid"])) ? $itemid = $_REQUEST["itemid"] : $itemid = "NULL" ;

if (isset($_REQUEST['t'])) {
	if (@$_REQUEST['t'] == @$_SESSION['T']) {
   // Form resubmission.
   nonterminal_error("Please do not use back or refresh when entering data.");
  } else {  
   // Record last submission to catch resubmission.
   $_SESSION['T'] = $_REQUEST['t'];   
  }
}

if ($obj->header[2] !== "") {
 // have already read or created an item so see what changes user requests.
 $obj->applyfromrequest();
 if ($sub == "Save" && $obj->valid) { 
  if ($obj->writedb()) {  
   // Successful save
   $obj->confirmfiled();
  } else {  
   // Failed to save
   $obj->showfail();
  }  
 } elseif($sub=="Delete") {  
  if ($obj->deletedb()) {
   unset($_SESSION[$obj->gettablename()]);  
   $obj->confirmdeleted();
  } else {  
   $obj->showfail();
  }
 } elseif($res=="restart") { 
  unset($_SESSION[$obj->gettablename()]);
  $obj->showchoose("User Setup","Enter to create a new item, or enter code, or enter text to reduce size of list","Choose","ALL") ;
 } else {
   // Invalid object
  $obj->showform();
 }
} elseif ($itemid=="") {
 // request to set up a new item 
 $obj->createblank();
 $obj->showform();
} elseif ($itemid == "NULL") {
 // First call. Give a select list.
 $obj->showchoose();
} else {
 // try reading the specific item
 if ($obj->readdb($itemid)) {  
  // Read in an item specified by itemid
  $obj->showform();
 } else { 
  // Otherwise just shwo a selectlist. Showchoose method works off itemid and from position
  $obj->showchoose();
 } 
}
?>